define(
		[ "PDUtilDir/util", "PDUtilDir/tool", "PDUtilDir/slidebar", "PDUtilDir/inputSelect", "PDUtilDir/fileupload/multiFileUpload", "Date", "DateCN", "css!DateCss", "PicView", "css!picViewCss" ],
		function(Util, Tool, Slidebar, inputSelect, MFU) {
			function addSupportInit($scope, $compile){
				return new addSupport($scope, $compile);
			};
			function addSupport($scope, $compile){
				var _this = this;
				this.entity = {};
				this.bind = {};
				this.$scope = $scope;
				this.$compile = $compile;
			};
			addSupport.fn = addSupport.prototype;
			addSupport.fn.digest = function(){
				 this.$scope.$digest();
			};
			addSupport.fn.run = function(data) {
				var _this = this;
				_this.entity = data;
				this.slidebars = Slidebar({
					size : 'lg',
					url : getServer()
							+ "/static/app/register/visitorInfos/views/update.html",
//					close : true,
					$scope: this.$scope,
					$compile: this.$compile,
					afterLoad : function($Panel) {
						_this.initialization();
					}
				});
			};
			addSupport.fn.initialization = function(){
				this.baseInit();
			};
			addSupport.fn.baseInit = function() {
				var _this = this;
				//加载code
				$.ajax({
					url : getServer()
							+ "/flea/hclv/visitor/selectVisitorImage.htmls",
					method : 'get',
					data: {
						visitorId: _this.entity.id
					},
					success : function(data) {
                        if (data.status != 200) {
                            return;
                        }
						_this.entity.images = data;
						_this.bind.images = data;
						_this.digest();
					}
				});
				//证件类型
				inputSelect.dropCache();
				inputSelect({
					id : "certificatesName",
					key : {
						id : "dictCode",
						name : "dictName",
						data : "data",
					},
					data : _this.$scope.cache.certificates,
					simpleData : true,
					// 启用文本搜索
					initData:[ _this.entity.certificates ],
					searchAble : false,
					callback : function(id) {
						_this.entity.certificates = id[0];
					}
				});
				$("#birthDate").datetimepicker({
		            //设置使用语言：cn是自定义的中文版本，还可以扩展其他语言版本
		            language : "cn",
		            //输出格式化
		            format : 'yyyy-mm-dd',
		            //直接选择‘今天’
		            todayBtn : true,
		            //设置最精确的时间选择视图
		            minView : 'month',
		            //高亮当天日期
		            todayHighlight : true,
		            //选择完毕后自动关闭
		            autoclose : true
		        });
				$("#birthDatete").datetimepicker('setDate', new Date(_this.entity.birthDate) );
				MFU.init({
	                placeAt:"license",
//	                allowPhyDelete:true,
	                allowDelete:true,
	                allowMC:true,
	                onUploadSuccess:function(file){
	                	_this.entity.image = {'resouceId':file.swordFileId,'path':file.swordFilePath}
	                },
	                onDeleteSavedFile:function(file){
	                	if(file == null)
	                		return;
	                	var i = 0;
	                    $.each(_this.entity.images, function(index, row){
	                    	if(row.resouceId == file.swordFileId){
	                    		i = index;
	                    		return
	                    	}
	                    });
	                    _this.entity.images.splice(i, 1);
	                    _this.bind.images.splice(i, 1);
	                    _this.digest();
	                },
	                onFilesQueued: function(files){
	                	var webUploader = this.webUploader, queuedFiles = this.queuedFiles;
                        $.each(files, function(index, file) {
                            if(ImageSuffix.indexOf(file.ext.toLowerCase()) < 0){
                                $.each(queuedFiles, function(index, item) {
                                    if(file.id == item.file.id){
                                        item.remove();
                                    }
                                });
                                return true;
                            }
	                		webUploader.makeThumb( file, function( error, src ) {
		                        if ( error ) {
		                        	Util.alert('不能预览');
		                            return;
		                        }
		                        _this.bind.images.push({
		                        	key: file.name,
		                        	path: src
		                        });
		                        _this.digest();
		                    }, 500, 300 );
                            if(queuedFiles.length == 0)
                                Util.alert(ImageSuffixNotSupport);

                            webUploader.upload();
						});
	                }
	            });
			};
			addSupport.fn.save = function() {
				var _this = this;
				if(!_this.entity.image){
					Util.alert('请点击上传按钮！');
					return;
				}
				$.ajax({
                    url : getServer() + "/flea/hclv/visitor/saveOrUpdate.htmls",
                    data : {
                        'model' : JSON.stringify(_this.entity)
                    },
                    success : function(data) {
                        if (data.status != 200) {
                            return;
                        }
                    	_this.$scope.grid.refresh();
                        Util.alert('成功');
                        _this.slidebars.close();
                    }
				});
			};
			return addSupportInit;
		});